// 云函数入口文件
const cloud = require('wx-server-sdk')
const request = require('request')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  return new Promise((resolve, reject) => {
    request({
        url: event.url,
        method: event.method || 'POST',
        json: event.json || true,
        headers: event.headers || null,
        body: event.body|| null,
        form: event.form || null,
    }, function (error, response, body) {
      // console.log("statusCode=", response.statusCode);
        if (!error && response.statusCode == 200) {
            try {
                console.log("body=", body);
                resolve(body)
            } catch (e) {
                reject()
            }
        }
    });
  });
}